import requests
url='https://nba.hupu.com/stats/players'
headers={'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0'}
resp=requests.get(url,headers=headers)
from lxml import etree
e=etree.HTML(resp.text)
nos=e.xpath('//table[@class="players_table"]/tbody/tr/td[1]/text()')
names=e.xpath('//table[@class="players_table"]/tbody/tr/td[2]/a/text()')
teams=e.xpath('//table[@class="players_table"]/tbody/tr/td[3]/a/text()')
score=e.xpath('//table[@class="players_table"]/tbody/tr/td[4]/text()')
hit=e.xpath('//table[@class="players_table"]/tbody/tr/td[5]/text()')
hit_rate=e.xpath('//table[@class="players_table"]/tbody/tr/td[6]/text()')

with open('NBA.text','w+',encoding='utf-8')as f:
#保存数据
    for no,nam,tea,scr,h,hr in zip(nos,names,teams,score,hit,hit_rate):
        f.write(f"排名：{no} 球员：{nam} 球队：{tea} 分数：{scr} 命中——出手：{h} 命中率：{hr}\n")